// pages/xiangqing/xiangqing.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:{
      id:1,
      title:"汉服女短袖连衣裙",
      imgurl1:"/tupian/xc/4.webp",
      imgurl2:"/tupian/xc/6.webp",
      imgurl3:"/tupian/xc/7.webp",
      jiage:4,
      yajin:200,
      leixin1:"短袖连衣裙",
      leixin2:"长袖连衣裙",
      leixin3:"无袖连衣裙"
    },
    openid:'',
    date:'2021-01-01',
    date1:'2021-01-01',
    leixin:'',
    number:1,
    feiyong:0,
    goumai:true,
    tijiao:true,
    gouwuche:true
  },
  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  bindDateChange1: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date1: e.detail.value
    })
  },
  dingdan:function(){
      this.setData({
        goumai:false,
        gouwuche:false
      })
  },
  zulin:function(){
    this.setData({
      goumai:false,
      tijiao:false
    })
  },
  quxiao:function(){
    this.setData({
      goumai:true,
      tijiao:true,
      gouwuche:true
    })
  },
  dianpu:function(){
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  DD:function(){
    wx.switchTab({
      url: '/pages/dingdan/dingdan',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      list:JSON.parse(options.b)
    })
    console.log(this.data.list)
    var that=this
    wx.getStorage({
        key: 'openid',
        success: function(res){
        that.setData({
        openid:res.data,
    })
    console.log(that.data.openid)
  }
  })
    console.log(this.data.list)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  formSubmit:function(e){
    console.log(e.detail.value.number)
    this.setData({
      number:e.detail.value.number
    })
    console.log(this.data.date)
    console.log(this.data.date1)
    
    let date1 = new Date(this.data.date)
    let date2 = new Date(this.data.date1)
    let s1 = date1.getTime();
    let s2 = date2.getTime();
    let t=(s2-s1);
    var d=parseInt(t / 1000 / 60 / 60 / 24)
    console.log(d);
    var feiyong=parseInt(d*this.data.list.rent/7)
    console.log(feiyong)
    feiyong=feiyong*this.data.number
    this.setData({
        feiyong:feiyong
    })
    console.log(this.data.feiyong)








   
    var url1=''
    if(!this.data.gouwuche){
      url1='http://localhost:80/reserve/insert'
    }
    else{
      url1='http://localhost:80/lease/insert'
    }
    wx.request({
      url: url1,
      method:"POST",
      data:{
        user_openid:this.data.openid,
        articlesid:this.data.list.id,
        starttime:this.data.date,
        overtime:this.data.date1,
        leixin:this.data.leixin,
        number:this.data.number,
        feiyong:this.data.feiyong
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded'
    },
    success:res=>{
      wx.showToast({
        title: '成功',
        icon: 'success',
        duration: 2000//持续的时间
      })
      this.setData({
        goumai:true,
        tijiao:true,
        gouwuche:true
      })
    }
    })
  },
  HandelItemChange:function(e){
    console.log(e.detail.value)
    this.setData({
      leixin:e.detail.value
    })
  },
  pinglun(){
    wx.navigateTo({
      url: '/pages/wupingpinglun/wupingpinglun?b='+this.data.list.id,
    })
  }
})